package com.inheritance.controller;

import com.inheritance.common.Result;
import com.inheritance.service.BannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Resource
    private BannerService bannerService;

    // 轮播图上传
    @PostMapping("/upload")
    public Result<Boolean> upload(@RequestParam("file") MultipartFile file) {
        Boolean ok = bannerService.upload(file);
        if (ok) {
            return Result.success("上传成功");
        }
        return Result.error("上传失败");
    }

    // 获取轮播图列表
    @GetMapping("/list")
    public Result<?> list() {
        return Result.success(bannerService.list());
    }

    // 删除轮播图
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable String id) {
      int i =   bannerService.delete(id);
      if (i > 0) {
          return Result.success("删除成功");
      } else {
          return Result.error("删除失败");
      }
    }
}